import { request } from './request'
// 不鉴权接口
const api = {
  detail: '/comInstance/detail',
  pageList: '/comInstance/findList',
  aggregate: '/comInstance/aggregate',
  aggregateList: '/comInstance/aggregateList',
}

// 详情
export interface IDetailParams {
  id: string | number
  templateName: string
}

export const detail = (params: IDetailParams) => {
  return request.get(`${api.detail}/${params.templateName}/${params.id}`)
}

// 分页列表
export interface IDicCode {
  name: string
  type: number
  typeKey: string
}

export interface IPageInfo {
  pageNum: number
  pageSize: number
}
export interface IPageListParams {
  conditions?: Record<string, unknown>
  dicCodes?: IDicCode[]
  fields?: Record<string, unknown>
  pageInfo?: IPageInfo
  sort?: Record<string, unknown>
  templateName: string
}

export const pageList = (params: IPageListParams) => {
  return request.post(api.pageList, params)
}

// 聚合查询
export interface IAggregateParams {
  cmdList: Record<string, unknown>[]
  templateName: string
}

export const aggregate = (params: IAggregateParams) => {
  return request.post(api.aggregate, params)
}

export const aggregateList = (params: any) => {
  return request.post(api.aggregate, params)
}
